<?php

/**
 * BonTransfert filter form base class.
 *
 * @package    SdCommerce
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseBonTransfertFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'reference'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'date_creation'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'date_validite'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'vehicule_id'                => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Vehicule'), 'add_empty' => true)),
      'conducteur_id'              => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Conducteur'), 'add_empty' => true)),
      'coconducteur_id'            => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Coconducteur'), 'add_empty' => true)),
      'departement_source_id'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('DepartementSource'), 'add_empty' => true)),
      'departement_destination_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('DepartementDestination'), 'add_empty' => true)),
      'employe_id'                 => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Employe'), 'add_empty' => true)),
      'observation'                => new sfWidgetFormFilterInput(),
      'duree_validite'             => new sfWidgetFormFilterInput(),
      'cloture'                    => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'contact_id'                 => new sfWidgetFormFilterInput(),
      'representant_id'            => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Representant'), 'add_empty' => true)),
      'statut'                     => new sfWidgetFormChoice(array('choices' => array('' => '', 'Affectation de Stock' => 'Affectation de Stock', 'Ajustement de Stock' => 'Ajustement de Stock', 'Confirmation du Bon de transfert' => 'Confirmation du Bon de transfert'))),
      'confirme'                   => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'valider'                    => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'etat_reglement'             => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'supprimer'                  => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'livre'                      => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'created_at'                 => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                 => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'deleted_at'                 => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'm_stock_article_list'       => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'StockArticle')),
    ));

    $this->setValidators(array(
      'reference'                  => new sfValidatorPass(array('required' => false)),
      'date_creation'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'date_validite'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'vehicule_id'                => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Vehicule'), 'column' => 'id')),
      'conducteur_id'              => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Conducteur'), 'column' => 'id')),
      'coconducteur_id'            => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Coconducteur'), 'column' => 'id')),
      'departement_source_id'      => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('DepartementSource'), 'column' => 'id')),
      'departement_destination_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('DepartementDestination'), 'column' => 'id')),
      'employe_id'                 => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Employe'), 'column' => 'id')),
      'observation'                => new sfValidatorPass(array('required' => false)),
      'duree_validite'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'cloture'                    => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'contact_id'                 => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'representant_id'            => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Representant'), 'column' => 'id')),
      'statut'                     => new sfValidatorChoice(array('required' => false, 'choices' => array('Affectation de Stock' => 'Affectation de Stock', 'Ajustement de Stock' => 'Ajustement de Stock', 'Confirmation du Bon de transfert' => 'Confirmation du Bon de transfert'))),
      'confirme'                   => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'valider'                    => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'etat_reglement'             => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'supprimer'                  => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'livre'                      => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'created_at'                 => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                 => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'deleted_at'                 => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'm_stock_article_list'       => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'StockArticle', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('bon_transfert_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addMStockArticleListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LigneBonTransfert LigneBonTransfert')
      ->andWhereIn('LigneBonTransfert.stock_article_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'BonTransfert';
  }

  public function getFields()
  {
    return array(
      'id'                         => 'Number',
      'reference'                  => 'Text',
      'date_creation'              => 'Date',
      'date_validite'              => 'Date',
      'vehicule_id'                => 'ForeignKey',
      'conducteur_id'              => 'ForeignKey',
      'coconducteur_id'            => 'ForeignKey',
      'departement_source_id'      => 'ForeignKey',
      'departement_destination_id' => 'ForeignKey',
      'employe_id'                 => 'ForeignKey',
      'observation'                => 'Text',
      'duree_validite'             => 'Number',
      'cloture'                    => 'Boolean',
      'contact_id'                 => 'Number',
      'representant_id'            => 'ForeignKey',
      'statut'                     => 'Enum',
      'confirme'                   => 'Boolean',
      'valider'                    => 'Boolean',
      'etat_reglement'             => 'Boolean',
      'supprimer'                  => 'Boolean',
      'livre'                      => 'Boolean',
      'created_at'                 => 'Date',
      'updated_at'                 => 'Date',
      'deleted_at'                 => 'Date',
      'm_stock_article_list'       => 'ManyKey',
    );
  }
}
